package com.atguigu.cart.vo;

import java.math.BigDecimal;
import java.util.List;

/**
 * 整体购物车
 */
public class Cart {
    private List<CartItem> items; //每个购物项

    private Integer countNum;   //商品总数量

    private Integer countType;  //商品种类数量

    private BigDecimal totalAmount = new BigDecimal("0"); //总金额

    private BigDecimal reduce = new BigDecimal("0");  //优惠金额

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        int count = 0;
        if(items != null && items.size() > 0){
            for (CartItem item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public Integer getCountType() {
        int count = 0;
        if(items != null && items.size() > 0){
            for (CartItem item : items) {
                count += 1;
            }
        }
        return count;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal total = new BigDecimal("0");
        //计算所有商品总价
        if(items != null && items.size() > 0){
            for (CartItem item : items) {
                if(item.getCheck()){
                    total = total.add(item.getTotalPrice());
                }
            }
        }
        //减去优惠金额
        total.subtract(reduce);
        return total;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
